<template>
  <view class="setting-container">
    <view class="setting-list">
      <!-- 消息推送 -->
      <view class="setting-item">
        <view class="setting-info">
          <text class="setting-title">消息推送</text>
          <text class="setting-desc">开启消息推送</text>
        </view>
        <switch
          :checked="messageNotification"
          @change="handleMessageSwitch"
          color="#4375FB"
        />
      </view>

      <!-- 处方自动审方 -->
      <view class="setting-item">
        <view class="setting-info">
          <text class="setting-title">处方自动审方</text>
          <text class="setting-desc">开启后接收到的处方将自动提醒审方</text>
        </view>
        <switch
          :checked="autoReview"
          @change="handleAutoReviewSwitch"
          color="#4375FB"
        />
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      messageNotification: true,
      autoReview: true,
    };
  },
  onLoad() {
    // 加载设置
    this.loadSettings();
  },
  methods: {
    // 加载设置
    loadSettings() {
      const messageNotification = uni.getStorageSync("messageNotification");
      const autoReview = uni.getStorageSync("autoReview");

      if (messageNotification !== "") {
        this.messageNotification = messageNotification;
      }
      if (autoReview !== "") {
        this.autoReview = autoReview;
      }
    },

    // 消息推送开关
    handleMessageSwitch(e) {
      this.messageNotification = e.detail.value;
      uni.setStorageSync("messageNotification", this.messageNotification);

      uni.showToast({
        title: this.messageNotification ? "已开启消息推送" : "已关闭消息推送",
        icon: "none",
        duration: 1500,
      });
    },

    // 自动审方开关
    handleAutoReviewSwitch(e) {
      this.autoReview = e.detail.value;
      uni.setStorageSync("autoReview", this.autoReview);

      uni.showToast({
        title: this.autoReview ? "已开启自动审方" : "已关闭自动审方",
        icon: "none",
        duration: 1500,
      });
    },
  },
};
</script>

<style scoped>
.setting-container {
  height: 94vh;
  background: #f5f5f5;
  overflow: hidden;
}

.setting-list {
  background: #ffffff;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 40rpx 30rpx;
  border-bottom: 1rpx solid #f0f0f0;
}

.setting-item:last-child {
  border-bottom: none;
}

.setting-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.setting-title {
  font-size: 32rpx;
  color: #333333;
  font-weight: 500;
  margin-bottom: 12rpx;
}

.setting-desc {
  font-size: 24rpx;
  color: #999999;
  line-height: 36rpx;
}
</style>
